package wli.app.util;

public class MyStringToInteger {
	private String input;
	private int output = 0;
	private String numbers = "0123456789-";
	boolean nagtive = false;

	public void setInput(String in) {
		input = in;
		if (input.startsWith("-")) {
			nagtive = true;
			input = in.substring(1);
		}
		
		for (int i = 0; i < input.length(); i++) {
			if (numbers.indexOf(input.charAt(i)) == -1) {
				System.out.println("this string can not convert to an integer.");
				break;
			}
		}

		int newnumb = 0;
		for (int i = 0; i < input.length(); i++) {
			newnumb = newnumb * 10;
			newnumb += Character.digit(input.charAt(i), 10);
		}
		
		if(nagtive) {
			newnumb = newnumb*(-1);
		}
		this.output = newnumb;
	}

	public int getOutput() {
		return output;
	}

}
